package com.bdqn.rooms.controller;


import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.bdqn.rooms.beans.Staff;
import com.bdqn.rooms.service.StaffService;
import com.bdqn.rooms.util.JedisTemlateUtil;
import com.bdqn.rooms.util.Result;
import com.bdqn.rooms.util.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author jack
 * @since 2019-05-14
 */
@Controller
@RequestMapping("/staff")
public class StaffController {
    @Resource
       private StaffService staffServiceimpl;
    @Autowired
       private JedisTemlateUtil jedisTemlateUtil;

    /**
     * 员工注册
     * @param staff
     * @return
     */
    @RequestMapping("/addStaff")
    @ResponseBody
    public Result addStaff(Staff staff){
        staffServiceimpl.insert(staff);
        return ResultUtil.success();
    }

    /**
     * 员工登录
     * @param staff
     * @return
     */
    @RequestMapping("/StaffLogin")
    @ResponseBody
    public boolean StaffLogin(Staff staff){
        Staff s = staffServiceimpl.selectOne(new EntityWrapper().eq("susername",staff.getSusername()));

        if (s!=null&&s.getSpassword().equals(staff.getSpassword())){
            jedisTemlateUtil.DepositIn(s,s.getSusername());
            return true;
        }
        return false;
    }
}

